

package jetbrains.buildServer.server.rest.data.locator;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;

public class EnumValue implements PlainValue {
  public static <E extends Enum<E>> EnumValue of(@NotNull Class<E> enumClass) {
    return new EnumValue(Arrays.stream(enumClass.getEnumConstants()).map(v -> v.name().toLowerCase()).collect(Collectors.toList()));
  }

  public static EnumValue of(@NotNull Collection<String> values) {
    return new EnumValue(values.stream().distinct().collect(Collectors.toList()));
  }

  public static EnumValue of(@NotNull String... values) {
    return new EnumValue(Arrays.stream(values).distinct().collect(Collectors.toList()));
  }

  private final List<String> myValues;
  private EnumValue(@NotNull List<String> values) {
    myValues = values;
  }

  @NotNull
  public List<String> getValues() {
    return myValues;
  }

  @Override
  public String getFormat() {
    return "['" + String.join("','") + "']";
  }
}